package org.csu.mypetstorems.controller;
import org.csu.mypetstorems.entity.Order;
import org.csu.mypetstorems.entity.PageBean;
import org.csu.mypetstorems.result.Result;
import org.csu.mypetstorems.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PutMapping("/orders")
    public Result<String> changeStateService(@RequestParam String status,@RequestParam String orderId) {
        if(orderService.changeState(status, orderId))
            return Result.success();
        else
            return Result.error("更新Order状态失败");
    }

    @GetMapping("/orders")
    public Result<PageBean<Order>> orderListWithConditionService(
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
            @RequestParam(required = false) String orderId,
            @RequestParam(required = false) String phone
    ) {
        PageBean<Order> pageBean = orderService.getOrderListWithCondition(pageNum, pageSize, orderId, phone);
        if(pageBean != null)
            return Result.success(pageBean);
        else
            return Result.error("获取Order条件查询失败");
    }
}
